package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.sc.nft.entity.TempCollectionHoldings;
import com.sc.nft.entity.UserConsensus;
import lombok.extern.slf4j.Slf4j;
import com.sc.nft.entity.UserCollectionConsensus;
import com.sc.nft.mapper.UserCollectionConsensusMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.util.List;

/**
 * 用户生态共识度表(sc_user_collection_consensus)数据DAO
 *
 * @author zxy
 * @description 由 Mybatisplus Code Generator 创建
 * @since 2024-09-11 14:15:00
 */
@Slf4j
@Repository
public class UserCollectionConsensusDao extends ServiceImpl<UserCollectionConsensusMapper, UserCollectionConsensus> {

    public UserCollectionConsensus getBuyUserIdAndCollectionId(Long userId, Long collectionId) {
        return lambdaQuery().eq(UserCollectionConsensus::getUserId, userId).eq(UserCollectionConsensus::getCollectionId, collectionId).one();
    }

    public List<UserCollectionConsensus> getBuyUserIdListAndCollectionId(List<Long> userIdList, Long collectionId) {
        return lambdaQuery().in(UserCollectionConsensus::getUserId, userIdList).eq(UserCollectionConsensus::getCollectionId, collectionId).list();
    }

    public void updateConsensus(Long id, BigDecimal consensusNum) {
        UpdateWrapper<UserCollectionConsensus> wrapper = new UpdateWrapper<>();
        wrapper.eq("id", id);
        wrapper.setSql("consensus_num=consensus_num+" + consensusNum);
        update(wrapper);
    }


    public List<UserCollectionConsensus> getUserCollectionConsensusListByUserId(Long userId) {
        LambdaQueryWrapper<UserCollectionConsensus> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(UserCollectionConsensus::getUserId, userId);
        wrapper.eq(UserCollectionConsensus::getIsDelete, Boolean.FALSE);
        return list(wrapper);
    }

    /**
     * 每天共识度初始化列表
     */
    public List<UserCollectionConsensus> synchronousConsensusDegreeList() {
        return baseMapper.synchronousConsensusDegreeList();
    }
}